package com.twu.biblioteca;

import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: ruchita
 * Date: 23/9/13
 * Time: 12:41 PM
 * To change this template use File | Settings | File Templates.
 */
public class MovieInfoPage {
    private JTable table1;
    public JPanel panel1;

    public MovieInfoPage() {
        DefaultTableModel t = new DefaultTableModel(new Object[]{"MovieName", "Year", "Director", "Rating"}, 0);
        t.addRow(new Object[]{"Movie Name", "Year", "Director", "Rating"});
        //Add movie from sample database MovieInformation
        MovieInformation m = new MovieInformation();
        m.createDatabase();
        HashMap<String, ArrayList> a = m.getMovieInfo();
        for (Map.Entry<String, ArrayList> e : a.entrySet()) {
            if(null==e.getValue().get(2))
                   t.addRow(new Object[]{e.getKey(), e.getValue().get(0), e.getValue().get(1), "N/A"});
            else
                t.addRow(new Object[]{e.getKey(), e.getValue().get(0), e.getValue().get(1), e.getValue().get(2)});
        }
        table1.setModel(t);

    }

    {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        panel1 = new JPanel();
        panel1.setLayout(new BorderLayout(0, 0));
        table1 = new JTable();
        panel1.add(table1, BorderLayout.CENTER);
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return panel1;
    }
}
